import React from 'react';
import styles from './Authorize.less';
import { Table } from 'antd';
import moment from 'moment';

const AuthorizeList = (props) => {

  const { correlateType, authorizeList, departmentLoading, rowSelection, currentPage, pageSize } = props;

  const columns = [
    { title: '序号', width: '15%', render: (text, record, index) => <span>{(index + 1) + (currentPage - 1) * pageSize}</span> },
    { title: correlateType == 0 ? "角色名称" : correlateType == 2 ? '应用名称' : '岗位名称', dataIndex: 'targetName', key: 'targetName', width: '30%' },
    { title: correlateType == 0 || correlateType == 2 ? "菜单名称" : '部门名称', dataIndex: 'subjectName', key: 'subjectName', width: '30%' },
    { title: '创建时间', dataIndex: 'createTime', key: 'createTime', width: '20%',
      render: (text, record, index) => {
        const createTime = text ? text.replace("T", " ") : "";
        const result = moment(createTime).format("YYYY-MM-DD");
        return <span>{result}</span>;
      }
    }
  ];

  return (
    <div className={ styles.listTable }>
      <Table
        bordered
        tableLayout={"auto"}
        rowSelection={rowSelection}
        columns={columns}
        dataSource={authorizeList}
        pagination={false}
        loading={departmentLoading}
        rowKey={record => record.key}
        scroll={{y: (window.innerHeight - 230)}}
      />
    </div>
  );
};

export default AuthorizeList;
